//
//  RouteScanView.m
//  DigiOps
//
//  Created by app on 2018/7/17.
//  Copyright © 2018年 俞渊华. All rights reserved.
//

#import "RouteScanView.h"
#import "LineDetail.h"
#import "PointModel.h"
#import "recordContent.h"

@interface RouteScanView()
//@property(nonatomic,strong) UIImageView* scanImage;
@end
@implementation RouteScanView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.scanImage = [[UIImageView alloc]init];
        //        self.remarkLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        //        self.remarkLabel.font = [UIFont xm_font:15.0];
        [self addSubview:self.scanImage];
        UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizer)];
        [self addGestureRecognizer:tapGesture];
    }
    return self;
}
-(void)tapGestureRecognizer{
    
}
-(void)setLine:(LineDetail *)line{
    _line=line;
    if ([MySingleton sharedMySingleton].finished) {
        self.scanImage.hidden=NO;
        self.hidden=NO;
//        [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
    }
    else{
    for (PointModel* pm in _line.soprouteArray) {
        if ([pm.content isEqualToString:@"不正常"]) {
            [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
            break;
        }
    }
    }
}
-(void)setLineF:(LineDetail *)line{
    for (PointModel* pm in _line.soprouteArray) {
        if ([pm.content isEqualToString:@"不正常"]) {
            [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
            break;
        }
    }
    if ([MySingleton sharedMySingleton].finished) {
        self.scanImage.hidden=NO;
        self.hidden=NO;
        [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
        if ([line.exceptionState isEqualToString:@"1"]) {
            self.scanImage.hidden=YES;
            self.hidden=YES;
            [MySingleton sharedMySingleton].exceptionRemark=line.exceptionRemark;
        }
        if (![line.exceptionRemark isEqualToString:@""]) {
            self.scanImage.hidden=YES;
            self.hidden=YES;
        }
        else{
            [self.scanImage setImage:[UIImage imageNamed:@"sop_okbtn"]];


            
        }
        //已完成内容有不正常就红色
        for (NSDictionary* pm in line.recordContents) {
            recordContent* rc=[recordContent mj_objectWithKeyValues:pm];
            if ([rc.content isEqualToString:@"不正常"]) {
                [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
                break;
            }
            
        }
    }
}
-(void)setModel:(RouteModel *)model{
    _model = model;
    //        self.taskLabel.text = @"巡逻任务";
    //    self.remarkLabel.text = @"备注";
    if ([MySingleton sharedMySingleton].finished) {
    }
    else{
    [self.scanImage setImage:[UIImage imageNamed:@"sop_okbtn"]];
    }
    //这是当时测试用的代码，按照设计来的
    if (model.ID==100000) {
        [self.scanImage setImage:[UIImage imageNamed:@"sop_problembtn"]];
        
        LineDetail* details=model.details[0];
        
    }
    
}
-(void)layoutSubviews{
    [super layoutSubviews];
    //    [self.taskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.centerX.mas_equalTo(self);
    //    }];
    [self.scanImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        //        make.right.mas_equalTo(self).offset(-30);
        //        if ([MySingleton sharedMySingleton].finished) {
        if (!self.isInRoute) {
            make.width.height.mas_equalTo(@20);
        }
        //        }
        
    }];
    
}
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}
@end
